{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit ErrorForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, BaseMsgForm, StdCtrls, ExtCtrls;

type
  TfrmError = class(TfrmBaseMessage)
    procedure FormShow(Sender: TObject);
    procedure btCentreClick(Sender: TObject);
    procedure btRightClick(Sender: TObject);
  private
    { Private declarations }
    FMessage: String;
    FHelpMsg: String;
  public
    { Public declarations }
    property ErrorMessage: String read FMessage write FMessage;
    property HelpMessage: String read FHelpMsg write FHelpMsg;
    class function ShowError(ErrorMessage: String): TModalResult; overload;
    class function ShowError(HelpMessage, ErrorMessage: String): TModalResult; overload;
  end;

var
  frmError: TfrmError;

implementation

{$R *.dfm}

uses Logging, Utilities;

procedure TfrmError.FormShow(Sender: TObject);
begin
  inherited;

  // Set error text
  lbDesc.Caption := FHelpMsg + sLineBreak + sLineBreak + FMessage;

  // Only enable logfile option if logging assigned
  btRight.Enabled := Assigned(LoggingInstance);
end;

procedure TfrmError.btCentreClick(Sender: TObject);
begin
  inherited;

  DisplayBrowserSupport;
end;

procedure TfrmError.btRightClick(Sender: TObject);
begin
  inherited;

  LoggingInstance.ViewLogFile;
end;

class function TfrmError.ShowError(ErrorMessage: String): TModalResult;
var
  HelpMessage: String;
begin
  // Use default help message
  HelpMessage := 'A fatal error has occurred and mediate needs to close. ' +
                 'Please contact @home media support and report the ' +
                 'following message:';
  Result := ShowError(HelpMessage, ErrorMessage);
end;

class function TfrmError.ShowError(HelpMessage, ErrorMessage: String): TModalResult;
var
  Error: TfrmError;
begin
  // Configure description & show modally
  Error := Self.Create(Application.MainForm);
  try
    Error.PopupParent := Application.MainForm;
    Error.ErrorMessage := ErrorMessage;
    Error.HelpMessage := HelpMessage;
    Result := Error.ShowModal;
  finally
    Error.Free;
  end;
end;


end.
